<?php
include 'header.php';

$sql_cnt="SELECT id FROM wish";

$result = $conn->query($sql_cnt);
$total_cnt = $result->num_rows;
$listRows = 5;
$total_pages = ceil($total_cnt/$listRows);


 $page = empty($_GET['p']) ? 1 : $_GET['P'];
 $page = ($page < 1) ? 1 : $page;
 $page = ($page > $total_pages) ? $total_pages: $page;
$sql = "SELECT * FROM  wish LIMIT ".($page-1) *5 ." , 5";
$result = $conn->query($sql);

$arrlist = array();

if ($result->num_rows > 0) {  
    // 输出每行数据
    while($row = $result->fetch_assoc()) {
        array_push($arrlist, $row);        
    }
} else {
    echo "0 results";
}
$conn->close();          
?>
<div id="right">
    <table border="1">
        <tr>
            <td>序号</td>
            <td>留言者</td>
            <td>留言内容</td>
            <td>留言时间</td>
            <td>操作</td>
        </tr>
        <?php foreach($arrlist as $vo ){?>
        <tr>
            <td><?php echo $vo['id'];?></td>
            <td><?php echo $vo['username'];?></td>
            <td><?php echo $vo['content'];?></td>
            <td><?php echo $vo['time_at'];?></td>
            <td><span><a>修改</a></span> | <span><a href="delete.php?id=<?php echo $vo['id'];?>">删除</a></span></td>
        </tr>
        <?php }?>
    </table>
    <div id="page"><?php 
    
         $s ="";
         for($i=1;$i<=$total_pages;$i++){
             
             
             
             $s .="<span><a href='?p=$i'>$i</a></span>";
             
         }
    
    
      echo $s;
    
    ?>
   
    </div>
</div>
